package com.qt.socket.tcpwork.work2;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author zsf
 * @Date 2023/10/5 15:27
 * @Version 1.0
 */
public class TcpServer {

    /**
     * TCP通信练习2---接收和反馈
     * 客户端:发送一条数据，接收服务端反馈的消息并打印服务器:接收数据并打印，再给客户端反馈消息
     */

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        InputStreamReader isr = new InputStreamReader(socket.getInputStream());
        OutputStream os = socket.getOutputStream();

        int len;
        System.out.println("接收到的数据: ");
        while ((len = isr.read()) != -1){
            System.out.print((char)len);
        }

        os.write("收到".getBytes());

        socket.close();
        serverSocket.close();




    }


}
